package logic

import (
	"Junior_two/subject/goods/goodsrpc/pb/goodRpc"
	"context"

	"Junior_two/subject/goods/goodsapi/internal/svc"
	"Junior_two/subject/goods/goodsapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsListLogic) GoodsList(req *types.ListRequest) (resp *types.ListResponse, err error) {
	// todo: add your logic here and delete this line
	r, e := l.svcCtx.GoodServer.GoodsList(l.ctx, &goodRpc.ListRequest{
		Page: req.Page,
		Name: req.Name,
	})
	if e != nil {
		return &types.ListResponse{}, nil
	}
	return &types.ListResponse{
		Total:    r.Total,
		ShowPage: r.ShowPage,
		NowPage:  r.NowPage,
		ConPage:  r.ConPage,
		Data:     r.Data,
	}, nil
}
